package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeMsg;
import com.ruoyi.grape.service.IGrapeMsgService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线上留言Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/msg")
public class GrapeMsgController extends BaseController
{
    @Autowired
    private IGrapeMsgService grapeMsgService;

    /**
     * 查询线上留言列表
     */
    @PreAuthorize("@ss.hasPermi('grape:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeMsg grapeMsg)
    {
        startPage();
        List<GrapeMsg> list = grapeMsgService.selectGrapeMsgList(grapeMsg);
        return getDataTable(list);
    }

    /**
     * 导出线上留言列表
     */
    @PreAuthorize("@ss.hasPermi('grape:msg:export')")
    @Log(title = "线上留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeMsg grapeMsg)
    {
        List<GrapeMsg> list = grapeMsgService.selectGrapeMsgList(grapeMsg);
        ExcelUtil<GrapeMsg> util = new ExcelUtil<GrapeMsg>(GrapeMsg.class);
        util.exportExcel(response, list, "线上留言数据");
    }

    /**
     * 获取线上留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:msg:query')")
    @GetMapping(value = "/{msgId}")
    public AjaxResult getInfo(@PathVariable("msgId") Long msgId)
    {
        return success(grapeMsgService.selectGrapeMsgByMsgId(msgId));
    }

    /**
     * 新增线上留言
     */
    @PreAuthorize("@ss.hasPermi('grape:msg:add')")
    @Log(title = "线上留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeMsg grapeMsg)
    {
        return toAjax(grapeMsgService.insertGrapeMsg(grapeMsg));
    }

    /**
     * 修改线上留言
     */
    @PreAuthorize("@ss.hasPermi('grape:msg:edit')")
    @Log(title = "线上留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeMsg grapeMsg)
    {
        return toAjax(grapeMsgService.updateGrapeMsg(grapeMsg));
    }

    /**
     * 删除线上留言
     */
    @PreAuthorize("@ss.hasPermi('grape:msg:remove')")
    @Log(title = "线上留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{msgIds}")
    public AjaxResult remove(@PathVariable Long[] msgIds)
    {
        return toAjax(grapeMsgService.deleteGrapeMsgByMsgIds(msgIds));
    }
}
